Fix string instance method closures on JS, Python, and JVM targets#12784
Draft
Copilot wants to merge 4 commits intodevelopmentfrom
Draft
Fix string instance method closures on JS, Python, and JVM targets#12784Copilot wants to merge 4 commits intodevelopmentfrom
Copilot wants to merge 4 commits intodevelopmentfrom
Conversation
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix string.charAt closure in generated JS
Fix string instance method closures on JS, Python, and JVM targets
Mar 10, 2026
Member
|
The python and JVM changes are fine, but JS, oof... |
Simn
added a commit
that referenced
this pull request
Mar 10, 2026
# Conflicts: # tests/unit/src/unit/issues/Issue8068.hx
Member
|
This needs optimization test if this First part of this test is one-line fix in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Taking a reference to a
Stringinstance method (e.g.str.charAt) crashes or produces wrong results on several targets. The typed case (f.charAt) and dynamic case ((d:Dynamic).charAt) are both affected.JavaScript (
src/generators/genjs.ml)$bindfix: Skiphx__closures__caching whentypeof o !== "object"(primitives are immutable). Usem.bind(o)directly instead, which avoids the crash.$sbindhelper: For dynamic/structural field accesses on potentially-string expressions (field name incharAt,indexOf,split, etc.), emit$sbind(o, "f")instead ofo.fin value context. The helper isfunction $sbind(o,f) { var m = o[f]; if( typeof m !== "function" ) return m; return m.bind(o); }— uses direct.bind()without caching to avoid addinghx__closures__as an enumerable property (which would corruptjs.Boot.__string_recand similar serialization).d.charAt(0)are generated asd.charAt(0)(JS auto-bindsthisfor dot-notation), skipping the$sbindwrapper.Python (
std/python/_std/String.hx)All inline instance methods were missing
@:runtime, causing a compile-time error ("Can't create closure on an extern inline member method"). Added@:runtimeto all of them; the Python generator already has correctFClosurehandling viapython_Boot.createClosure.JVM (
src/generators/genjvm.ml,std/jvm/_std/String.hx)FClosure(Some(String,_), cf)was callingjava.lang.String.charAt(int)directly, which returnscharnotString, causingNoSuchMethodError. Redirected these closures throughJvm.readField, which already dispatches all String methods viaStringExtwrappers.String.hx:charCodeAtandindexOfwereinlinewithout@:runtime, preventing closure creation at the type-checker level.Test
Issue8068.hxtarget guard extended fromhl || lua || interp || phpto also includejs || python || jvm.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.